#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
int main()
{
	int q = 0;
	scanf("%d", &q);
	char ch1[1000] = { 0 };
	scanf("%s", ch1);
	while (q--)
	{
		int x = 0;
		scanf("%d", &x);
		int a = 0;
		int b = 0;
		char ch2[1000] = { 0 };
		if (1 == x)
		{
			scanf("%s", ch2);
			strcat(ch1, ch2);
			printf("%s\n", ch1);
		}
		else if (2 == x)
		{
			scanf("%d%d", &a, &b);
			memmove(ch1, ch1 + a, b);
			ch1[b] = 0;
			printf("%s\n", ch1);
		}
		else if (3 == x)
		{
			scanf("%d", &a);
			scanf("%s", ch2);
			strcat(ch2, ch1 + a);
			ch1[a] = 0;
			strcat(ch1, ch2);
			printf("%s\n", ch1);
		}
		else if (4 == x)
		{
			scanf("%s", ch2);
			char* p = strstr(ch1, ch2);
			if (!p)
			{
				printf("-1\n");
				continue;
			}
			printf("%d\n", p - ch1);
		}
	}
	return 0;
}